package com.boot.security.server.dao.mffl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import com.boot.security.server.model.mffl.Vo.MfflChatContentVo;
import com.boot.security.server.model.mffl.Vo.MfflMappingVo;
import com.boot.security.server.model.mffl.Vo.SystemMfflMappingVo;
import org.apache.ibatis.annotations.*;

import com.boot.security.server.model.mffl.MfflMapping;

@Mapper
public interface MfflMappingDao {

    @Select("select * from mffl_mapping t where t.id = #{id}")
    MfflMapping getById(Long id);

    SystemMfflMappingVo getSystemMfflMappingVoById(Long id);

    @Delete("delete from mffl_mapping where id = #{id}")
    int delete(Long id);

    int update(MfflMapping mfflMapping);

    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into mffl_mapping(user_id, lawyer_id, firstTime, startTime, createTIme, updateTime) values(#{userId}, #{lawyerId}, #{firstTime}, #{startTime}, now(), now())")
    int save(MfflMapping mfflMapping);

    int count(@Param("params") Map<String, Object> params);

    List<SystemMfflMappingVo> list(@Param("params") Map<String, Object> params, @Param("offset") Integer offset, @Param("limit") Integer limit);

    MfflMappingVo getMfflMappingByUserIdAndLawyerId(@Param("sendId") Long isendId, @Param("receiveId") Long receiveId);

    //出现问题是修改结束时间
    @Update("update mffl_mapping set firstTime = #{firstTime},endTime = #{endTime},updateTime = now() where id = #{id}")
    void updateFirstTime(@Param("id") Long id, @Param("firstTime") int firstTime, @Param("endTime") Date endTime);

    //修改开始时间
    @Update("update mffl_mapping set startTime = #{startTime},endTime = null,updateTime = now() where id = #{id}")
    void updateFirstTimeStart(@Param("id") Long id, @Param("startTime") Date startTime);

    //消息中心-消息列表
    List<MfflChatContentVo> getMyMessage(@Param("userId") Long id);


    //查询用户与律师对应关系记录
    @Select("SELECT * FROM mffl_mapping t WHERE t.user_id = #{userid} AND t.lawyer_id = #{lawyerid}")
    MfflMapping getuserLawyermapping(@Param("userid") Integer userid,@Param("lawyerid")Integer lawyerid);

    //消息中心-消息列表 新的
    //用户
    List<MfflMappingVo> getMyMessageList(@Param("where") String where, @Param("userid") Integer userid);
    //律师端
    List<MfflMappingVo> getMyMessageListLaywer(@Param("where") String where, @Param("userid") Integer userid);
    @Update("update mffl_mapping set content = #{content},status = 1,finallyTime = now() where id = #{id} ")
    void updateContent(@Param("content") String content, @Param("id") Long id);
    @Update("update mffl_mapping set status = 0 where id = #{id} ")
    void updateMappingContentStatus(Integer mappingId);

}
